//
//  ChartView.m
//  intelligent
//
//  Created by Ace Portgas on 2024/3/28.
//

#import "ChartView.h"
@interface ChartView()
@property (nonatomic,strong) UIButton * closeBtn;
@property (nonatomic,strong) UIButton * okBtn;
@property (nonatomic,strong) UIImageView * imageView;
@property (nonatomic,strong) UILabel * titleLabel;
@end

@implementation ChartView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.6];
        
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn addTarget:self action:@selector(clickCloseBtn) forControlEvents:UIControlEventTouchUpInside];
        [_closeBtn setImage:SQGetImage(@"取消") forState:UIControlStateNormal];
        [self addSubview:_closeBtn];
        [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self).offset(-37);
            make.top.mas_equalTo(self).offset(128);
            make.size.mas_offset(CGSizeMake(40, 40));
        }];
        
        _imageView = [[UIImageView alloc]init];
        _imageView.image = SQGetImage(@"积分1");
        [self addSubview:_imageView];
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(CGSizeMake(261, 261));
            make.centerX.mas_equalTo(self.mas_centerX);
            make.top.mas_equalTo(self.closeBtn).offset(16);
        }];
        
        _titleLabel = [UILabel new];
        _titleLabel.font = FONT_MEDIUM(18);
        _titleLabel.textColor = UIColor.whiteColor;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.imageView);
            make.bottom.equalTo(self.imageView.mas_bottom).offset(-34);
        }];
        
        _okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_okBtn addTarget:self action:@selector(clickOKBtn) forControlEvents:UIControlEventTouchUpInside];
        [_okBtn setTitle:SQNSLocalString(@"确定") forState:UIControlStateNormal];
        [_okBtn setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
        [_okBtn setBackgroundImage:SQGetImage(@"矩形4") forState:UIControlStateNormal];
        [self addSubview:_okBtn];
        [_okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(CGSizeMake(195, 40));
            make.centerX.mas_equalTo(self.mas_centerX);
            make.top.mas_equalTo(self.imageView.mas_bottom).offset(7);
        }];
    }
    return self;
}
- (void)setNeedIntegral:(int)needIntegral{
    _needIntegral = needIntegral;
    self.titleLabel.text = [NSString stringWithFormat:@"%@%d%@",SQNSLocalString(@"是否消耗"),needIntegral,SQNSLocalString(@"积分制作图片")];
    self.titleLabel.keywords = [NSString stringWithFormat:@"%d",needIntegral];
    self.titleLabel.keywordsFont = FONT_MEDIUM(24);
    [self.titleLabel getLableSizeWithMaxWidth:200];
}
-(void)clickCloseBtn{
    if (self.ClickCancelBlock) {
        self.ClickCancelBlock();
    }
}

-(void)clickOKBtn{
    [Manager SQ_SetObject:[NSString stringWithFormat:@"%d",_needIntegral] FormKey:@"needIntegral"];
    if (self.ClickOKBlock) {
        self.ClickOKBlock();
    }
}

@end
